# -*- coding: utf-8 -*-
# @Time : 2021/4/6 10:17
# @Author : Orange
# @File : get_data.py

import requests

BIGDATA_DOMAIN = 'http://bigdata-platapi.fnwintranet.com'

BIGDATA_USERKEY = "a95c34cf34deb5a2d0af84f3aea2a616_algorithm-engine-flask"


def get_iv_data(start_time, end_time, equip_id, station_id, equip_mk):
    tags = {
        "equipID": equip_id,
        "equipMK": equip_mk,
        "staId": station_id
    }
    d = {
        "dataSource": "EMS",
        "endTime": end_time,
        "isClean": False,
        "listQueries": [
            {
                "aggregator": "avg",
                "downsample": "15m-avg-none",
                "explicitTags": True,
                "metric": "EMS.TcprAirOut",
                "tags": tags
            },
            {
                "aggregator": "avg",
                "downsample": "15m-avg-none",
                "explicitTags": True,
                "metric": "EMS.TcwIn",
                "tags": tags
            },
            {
                "aggregator": "avg",
                "downsample": "15m-avg-none",
                "explicitTags": True,
                "metric": "EMS.Pelec",
                "tags": tags
            },
            {
                "aggregator": "avg",
                "downsample": "15m-avg-none",
                "explicitTags": True,
                "metric": "EMS.STecr",
                "tags": tags
            },
            {
                "aggregator": "avg",
                "downsample": "15m-avg-none",
                "explicitTags": True,
                "metric": "EMS.IratioCpr",
                "tags": tags
            },
            {
                "aggregator": "avg",
                "downsample": "15m1h-avg-none",
                "explicitTags": True,
                "metric": "EMS.TcwOut",
                "tags": tags
            },
            {
                "aggregator": "avg",
                "downsample": "15m-avg-none",
                "explicitTags": True,
                "metric": "EMS.TchwIn",
                "tags": tags
            },
            {
                "aggregator": "avg",
                "downsample": "15m-avg-none",
                "explicitTags": True,
                "metric": "EMS.TchwOut",
                "tags": tags
            },
            {
                "aggregator": "avg",
                "downsample": "15m-avg-none",
                "explicitTags": True,
                "metric": "EMS.PArefEva",
                "tags": tags
            },
            {
                "aggregator": "avg",
                "downsample": "15m-avg-none",
                "explicitTags": True,
                "metric": "EMS.PArefCond",
                "tags": tags
            }

        ],
        "startTime": start_time,
        "userKey": BIGDATA_USERKEY
    }

    url = BIGDATA_DOMAIN + '/internal/bigdata/time_series/get_history'
    r = requests.post(url, json=d)
    return r.json()
